1. Field of the Invention
This invention relates in general to database management systems performed by computers, and in particular, to the optimization of queries using indices for summary tables.
2. Description of Related Art
Computer systems incorporating Relational DataBase Management System (RDBMS) software using a Structured Query Language (SQL) interface are well known in the art. The SQL interface has evolved into a standard language for RDBMS software and has been adopted as such by both the American Nationals Standard Institute (ANSI) and the International Standards Organization (ISO).
For most RDBMS software, combinations of base tables and views are used to access data stored in the database. A view definition includes a query that, if processed, provides a temporary result table based on the results of the query at that point in time. Using an INSERT statement and an appropriately defined table in the database, the temporary results table can be stored in the database. To refresh this table, the user would need to perform a DELETE from the table and then perform the INSERT again.
Users can directly query against a table in this manner, provided that the users are aware how the results were derived. Generally, the RDBMS software is not aware that such a table is any different from any other table in the database. However, this table cannot be used by an optimizer within the RDBMS software to improve performance, even though the table may contain data that would drastically improve the performance of other queries.
This leads to the idea of summary tables (also known as materialized views) as envisioned by the present invention. These tables are similar to the created table described above, except that the definition of the table is based on a xe2x80x9cfull selectxe2x80x9d (much like a view) that is materialized in the table. The columns of the table are based on the elements of the select list of the full select.
Summary tables are important for query optimization in data warehouse applications. There are extensive research activities and literature on summary tables and materialized views, as disclosed in the following publications, all of which are incorporated by reference herein:
1. L. S. Colby, R. L. Cole, E. Haslam, N. Jazaeri, G. Johnson, W. J. McKenna, L. Schumacher, D. Wilhite. Red Brick Vista: Aggregate Computation and Management. Proceedings of the 14th Int""l. Conference on Data Engineering, Orlando, Fla., 1998.
2. R Bello, K. Dias, A. Downing, J. Feenan, J. Finnerty, W. Norcott, H. Sun, A.
Witkowski, M. Ziauddin. Materialized Views In Oracle. Proceedings of the 24th VLDB Conference, New York, 1998.
3. D. Srivastava, S. Dar, H. Jagadish, A. Levy. Answering Queries with Aggregation Using Views. Proceedings of the 22nd VLDB Conference, Mumbai, India, 1996.
So far, the state of the art has focused on query rerouting using materialized views and incremental maintenance of materialized views. However, there is increasing need to optimize queries through the use of indices, especially unique indices that are defined on base tables referenced in the materialized views.
To overcome the limitations in the prior art described above, and to overcome other limitations that will become apparent upon reading and understanding the present specification, the present invention discloses a method, apparatus, and article of manufacture for optimizing a query by deriving uniqueness for indices on the summary tables. The query is analyzed to determine whether a summary table can be used to answer the query. A determination is made whether an index of the summary table is unique based on a query definition of the summary table. During query optimization phase, proving the existence of a unique index on the summary table further enables query optimization. For example, proving uniqueness may allow an optimizer function to remove a sort requirement by proving the generalized 1-tuple condition based on the techniques described in U.S. Pat. No. 5,615,361, entitled xe2x80x9cExploitation of Uniqueness Properties using 1-Tuple Condition for the Optimization of SQL Queriesxe2x80x9d, issued Mar. 25, 1997, to Ting Y. Leung et al., which patent is incorporated by reference herein. Similarly, proving index uniqueness may allow the optimizer to generate an efficient xe2x80x9cearly-outxe2x80x9d plan when at most one row will be returned as the answer set.